<?php
    class NewsController extends Main_Controller_Action
    {
        public function init()
        {
            $this->loadTemplates();
            $db = Zend_Registry::get('db');
        }
        
        public function indexAction()
        {
            $this->view->headTitle('uMarket - Tin tức');
            $category = new AdminDthink_Model_Category();
            $rows = $category->listVoucher(29);
            $this->view->data = $rows;
        }
        
        public function categoryAction()
        {
            $cat_id = $this->_request->getParam('id');
            $category = new AdminDthink_Model_Category();
            $cat_name = $category->getCatNameById($cat_id);
            $this->view->cat_id = $cat_id;
            $this->view->cat_name = $cat_name;
            $this->view->headTitle('uMarket - ' . $cat_name);
            
            $news = new Default_Model_News();
            $adapter = new Zend_Paginator_Adapter_DbSelect($news->listNewsByCategory($cat_id));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(5);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }
        
        public function detailsAction()
        {
            $news_id = $this->_request->getParam('id');
            $news = new Default_Model_News();
            $this->view->data = $news->getNewsById($news_id);
            $category = new AdminDthink_Model_Category();
            $this->view->cat_name = $category->getCatNameById($this->view->data['cat_id']);
            $this->view->headTitle('uMarket - ' . $this->view->cat_name);
            
            $this->view->day = $news->convertDayOfWeek($this->view->data['day']);
        }
    }
